/*
  - @Author: Guoyh
  - @Date: 2023-08-14 10:40:47

* @LastEditTime: 2023-11-15 19:39:26
* @LastEditors: Please set LastEditors

  - @Description:

* @FilePath: \nodex\nodecmp\op_lmh.go
  - hnxr
*/
package nodecmp

import (
	"gitee.com/hnxr_1/nodex"
)

//0:> 1>= 2 < 3:<= 4== 5 !=
//M

func init() {
	nodex.Reister(new(Lmh))
}

type Lmh struct {
	nodex.Node
	X nodex.Double  `remark:"输入"`
	L nodex.Double  `remark:"下限"`
	D nodex.Double  `remark:"迟滞宽度"` //迟滞宽度
	Y nodex.Boolean `remark:"输出Y,,out"`
}

func (m *Lmh) GetModelID() int {
	return nodex.ModCmp
}

func (m *Lmh) GetName() string {
	return "LMH"
}

/**
 * @description: 节点信息
 * @return {*}
 */
func (m *Lmh) RegData() []byte {
	return nodex.MakeRegData(m, "低限迟滞", m.GetName(), "")
}

// //0:> 1>= 2 < 3:<= 4== 5 !=
func (m *Lmh) Calc() (err error) {
	if m.EnQ {
		if *m.X.Bad || *m.L.Bad || *m.D.Bad {
			m.Bad = true
			return //不计算
		}
	}

	m.Bad = false
	if m.X.Value <= m.L.Value {
		m.Y.Value = true
		return
	}
	if m.X.Value > (m.L.Value + m.D.Value) {
		m.Y.Value = false
		return
	}

	return
}
